API: widget: Add gtk_widget_get_allocated_size()
authorBenjamin Otte <otte@redhat.com>
Mon, 14 Sep 2015 04:11:36 +0000 (06:11 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 28 Oct 2015 18:44:27 +0000 (19:44 +0100)
See docs for what this is.

docs/reference/gtk/gtk3-sections.txt
gtk/gtkwidget.c
gtk/gtkwidget.h
gtk/gtkwidgetprivate.h

index 453fdacbaf26bac60314c2d6d0610cb53f904e16..b352d13aa488020080fb7b3e93f833f4af1272f0 100644 (file)
@@ -5553,6 +5553,7 @@ gtk_widget_get_allocated_height
 gtk_widget_get_allocation
 gtk_widget_set_allocation
 gtk_widget_get_allocated_baseline
+gtk_widget_get_allocated_size
 gtk_widget_get_clip
 gtk_widget_set_clip
 gtk_widget_get_app_paintable
index 5cac170aeecd8e4b281fe8ae9c331f5409f60385..cb2a178364790a6425804aeaef04dfe5ab08b03b 100644 (file)
@@ -5864,6 +5864,9 @@ gtk_widget_size_allocate_with_baseline (GtkWidget     *widget,
   old_baseline = priv->allocated_baseline;
   real_allocation = *allocation;
 
+  priv->allocated_size = *allocation;
+  priv->allocated_size_baseline = baseline;
+
   adjusted_allocation = real_allocation;
   if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
     {
@@ -8898,6 +8901,8 @@ _gtk_widget_set_visible_flag (GtkWidget *widget,
       priv->allocation.width = 1;
       priv->allocation.height = 1;
       memset (&priv->clip, 0, sizeof (priv->clip));
+      memset (&priv->allocated_size, 0, sizeof (priv->allocated_size));
+      priv->allocated_size_baseline = 0;
     }
 }
 
@@ -15532,6 +15537,42 @@ _gtk_widget_set_simple_clip (GtkWidget     *widget,
   gtk_widget_set_clip (widget, &clip);
 }
 
+/**
+ * gtk_widget_get_allocated_size:
+ * @widget: a #GtkWidget
+ * @allocation: (out) (allow-none): a pointer to a #GtkAllocation to copy to
+ * @baseline: (out) (allow-none): a pointer to an integer to copy to
+ *
+ * Retrieves the widget’s allocated size.
+ *
+ * This function returns the last values passed to
+ * gtk_widget_size_allocate_with_baseline(). The value differs from
+ * the size returned in gtk_widget_get_allocation() in that functions
+ * like gtk_widget_set_halign() can adjust the allocation, but not
+ * the value returned by this function.
+ *
+ * If a widget is not visible, its allocated size is 0.
+ *
+ * Since: 3.20
+ */
+void
+gtk_widget_get_allocated_size (GtkWidget     *widget,
+                               GtkAllocation *allocation,
+                               int           *baseline)
+{
+  GtkWidgetPrivate *priv;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (allocation != NULL);
+
+  priv = widget->priv;
+
+  if (allocation)
+    *allocation = priv->allocated_size;
+  if (baseline)
+    *baseline = priv->allocated_size_baseline;
+}
+
 /**
  * gtk_widget_get_allocation:
  * @widget: a #GtkWidget
index 67441de36f6b78eaeae36d8e7625023070278fd0..e98c537b347dc1f296168ba5ca32cf5b83df7f60 100644 (file)
@@ -918,6 +918,10 @@ GDK_AVAILABLE_IN_ALL
 int                   gtk_widget_get_allocated_height   (GtkWidget     *widget);
 GDK_AVAILABLE_IN_3_10
 int                   gtk_widget_get_allocated_baseline (GtkWidget     *widget);
+GDK_AVAILABLE_IN_3_20
+void                  gtk_widget_get_allocated_size     (GtkWidget     *widget,
+                                                         GtkAllocation *allocation,
+                                                         int           *baseline);
 
 GDK_AVAILABLE_IN_ALL
 void                  gtk_widget_get_allocation         (GtkWidget     *widget,
index 6f49d245d7a33d382dc6e7f921e349de160f69a3..aefa4f8699a8985f97a0e1d8d187eb11f58c5cf1 100644 (file)
@@ -130,6 +130,8 @@ struct _GtkWidgetPrivate
   GtkStyleContext *context;
 
   /* The widget's allocated size */
+  GtkAllocation allocated_size;
+  gint allocated_size_baseline;
   GtkAllocation allocation;
   GtkAllocation clip;
   gint allocated_baseline;